#include "BieuThucTong.h"

BieuThucTong::BieuThucTong()
{
}

BieuThucTong::BieuThucTong(BieuThuc* bt1, BieuThuc* bt2)
{
	this->bieuThuc1 = bt1;
	this->bieuThuc2 = bt2;
}

BieuThucTong::~BieuThucTong()
{
	delete bieuThuc1;
	delete bieuThuc2;
}

double BieuThucTong::tinhGiaTri(double x)
{
	return bieuThuc1->tinhGiaTri(x) + bieuThuc2->tinhGiaTri(x);
}

//BieuThuc* BieuThucTong::tinhDaoHam(){
//	BieuThuc* daoHambt1 = bieuThuc1->tinhDaoHam();
//	BieuThuc* daoHambt2 = bieuThuc2->tinhDaoHam();
//
//	BieuThuc* kq = new BieuThucTong(daoHambt1, daoHambt2);
//	return kq;
//}

BieuThuc* BieuThucTong::timDaoHam()
{
	BieuThuc* daoHambt1 = bieuThuc1->tinhDaoHam();
	BieuThuc* daoHambt2 = bieuThuc2->tinhDaoHam();

	BieuThuc* kq = new BieuThucTong(daoHambt1, daoHambt2);
	return kq;
}

void BieuThucTong::daoDauBieuThuc()
{
	bieuThuc1->daoDauBieuThuc();
	bieuThuc2->daoDauBieuThuc();
}

string BieuThucTong::xuatChuoi()
{
	string kqbt1 = bieuThuc1->xuatChuoi();
	string kqbt2 = bieuThuc2->xuatChuoi();

	if(kqbt1 == "")
		return kqbt2;
	else
	{
		if(kqbt2 == "")
			return kqbt1;
		else
			return "(" + kqbt1  + "+" + kqbt2 + ")";
	}
}
